<html>

<head>
    <meta charset="UTF-8">
    <title>打印销售单</title>
    <link rel="stylesheet" type="text/css" href="../../../Themes/default/easyui.css">
    <link rel="stylesheet" type="text/css" href="../../../Themes/icon.css">
    <link rel="stylesheet" type="text/css" href="../../../CSS/demo.css">
    <link rel="stylesheet" type="text/css" href="../../../CSS/common.css">
    <link rel="stylesheet" type="text/css" href="../../../CSS/print.css">

</head>
<style>
    tr {
        height: 20px;
    }
</style>

<body>
    <div id="printContent"></div>
</body>
<script type="text/javascript" src="../../../JS/common.js"></script>
<script type="text/javascript" src="../../../JS/jquery.min.js"></script>
<script type="text/javascript" src="../../../JS/jquery.easyui.min.js"></script>
<script type="text/javascript" src="../../../JS/pageprint.js"></script>
<script type="text/javascript">
    function SalesOrderPrint() {
        this.PAGE_NUM = 6;
        this.printDetailArr = ["INDEX", "INTERNAL_NAME", "UNIT_NAME", "AMOUNT", "UNIT_PRICE", "SUM"];
        this.headerDataArr = ["CUSTOMER_NAME", "ORDER_NO", "DISTRIBUTION_DATE", "MEMO"];
        this.detailDataArr = ["INTERNAL_NAME", "UNIT_PRICE", "UNIT_NAME", "AMOUNT", "SUM"];
        this.addSumInfo = function (obj, data) {
            var newTr = obj.insertRow();
            var newTd = new Array();
            newTd[0] = newTr.insertCell();
            newTd[0].innerText = "合计";
            newTd[1] = newTr.insertCell();
            newTd[1].innerText = "";
            newTd[2] = newTr.insertCell();
            newTd[2].innerText = "";
            newTd[3] = newTr.insertCell();
            newTd[3].innerText = data.LUMP_AMOUNT;
            newTd[4] = newTr.insertCell();
            newTd[4].innerText = "";
            newTd[5] = newTr.insertCell();
            newTd[5].innerText = "¥" + data.LUMP_SUM;
        }
    }
    extend(SalesOrderPrint, OrderPrint);
    var remote_data_url = "";
    var orderData = new SalesOrderPrint();
    var paramid = getID(); /*得到当前界面的id*/
    var printType = paramid.substr(0, 1);
    var baseUrl = "";
    var id = paramid.substr(2); //获取所有的数据
    if (printType == "A") {
        remote_data_url = RemoteLinkAddress + '/logistics/originalorder/getaorder.do?IDS=' + id;
        baseUrl = "/logistics/originalorder";
    }
    if (printType == "B") {
        remote_data_url = RemoteLinkAddress + '/logistics/salesorder/getborder.do?IDS=' + id;
        baseUrl = "/logistics/salesorder";
    }
    $(document).ready(function () {
        loadRemote();
        bulkPrintCount(id, baseUrl);
    });

    function pageprint() {
        if (confirm("是否打印")) {
            print();
        }
    }

    function loadRemote() {
        $.ajax({
            type: "get",
            url: remote_data_url,
            dataType: "json",
            success: function (result) {
                try {
                    orderData.parseOrderData(result);
                } catch (e) {
                    console.log(e.message);
                }
                CreateHTML(orderData.DATA);
            }
        });
    }

    function CreateHTML(_data) {
        var content = "";
        var content_indx = 0;
        for (var i = 0; i < _data.length; i++) {
            if (i == _data.length - 1) {
                content = "<div class='div_print_info_portait' style='height:auto'>";
            } else {
                content = "<div class='div_print_info_portait PageNext' style='height:auto'>";
            }
            content += "<h1 align = 'center'> 绵阳市高水农副产品批发有限公司销售单</h1>
            <table cellspacing = '6' class='noborder'>
                <tr>
                    <th width='10%'> 配送时间 </th>
                    <td width='12%'>
                        <input type = 'text' value='" + _data[i].DISTRIBUTION_DATE + "'class = 'print_text_style'  style='width:100%'/ >
                    </td>
                    <th width='10%'> 订单编号 </th> 
                        <td width='18%'>
                            <input type = 'text' value='" + _data[i].ORDER_NO + "'class = 'print_text_style'  style='width:100%'/ >
                        </td> <th width='10%'> 
                        客户名称 
                    </th> 
                    <td width='40%'>
                        <input type = 'text' value='" + _data[i].CUSTOMER_NAME + "'class = 'print_text_style'  style='width:100%'/ >
                    </td> 
                </tr> 
            </table> 
            <table class = 'altrowstable printtable'id = 'SalesTable'style = 'margin-top: 0px; line-height:4px;' >
                <tr >
                    <th> 序号 </th>
                    <th> 品名 </th> 
                    <th> 单位 </th> 
                    <th> 数量 </th> 
                    <th> 单价 </th> 
                    <th> 金额 </th> 
                </tr> 
            </table>
            <table cellspacing = '6' class='noborder' >
                <tr>
                    <td>备注</td>
                    <td>
                        <input type='text' value='" + _data[i].MEMO + "' class='print_text_style' style='width:100%'/>
                    </td>
                </tr>
                <tr>
                    <td width='10%'> 送货人 </td> 
                    <td width='20%'>
                        <input type = 'text' class = 'print_text_style'  style='width:100%'/ >
                    </td>
                    <td width='10%'> 收货人 </td> 
                    <td width='20%'>
                        <input type = 'text' class = 'print_text_style'  style='width:100%'/ >
                    </td> 
                    <td width='10%'> 
                        <span> 第" + _data[i].PAGE + "页共" + _data[i].TOTALPAGE + "页</span>
                    </td> 
                    <td width='20%'>
                        <input type = 'text' class = 'print_text_style'  style='width:100%'/ >
                    </td> 
                </tr> 
            </table>";
            $("#printContent").append(content);
            content_indx = content_indx + 1;
            $("#SalesTable").attr("id", "SalesTable" + content_indx);
            var rowdata = _data[i].rows;
            var s = document.getElementById("SalesTable" + content_indx);
            try {
                orderData.displayDetailInfo(s, rowdata);
                if ("LUMP_SUM" in _data[i]) {
                    orderData.addSumInfo(s, _data[i]);
                }
            } catch (e) {
                console.log(e.message);
            }
        }
    }
</script>

</html>